<template>
  <!-- 视频库 -->
  <div>
    <!-- 搜索 -->
    <div class="search-area">
      <div class="form">
        <el-form
          :model="listQuery"
          ref="listQuery"
          size="small"
          :inline="true"
          label-width="145px"
        >
          <el-form-item :label="$t('开始时间') + '：'">
            <el-date-picker
              v-model="listQuery.startTime"
              type="date"
              size="medium"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              :placeholder="$t('选择开始时间')"
              :picker-options="pickerOptionsStart"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item :label="$t('结束时间') + '：'">
            <el-date-picker
              v-model="listQuery.endTime"
              type="date"
              size="medium"
              :placeholder="$t('选择结束时间')"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              :picker-options="pickerOptionsEnd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item :label="$t('文件名称') + '：'" prop="resourceName">
            <el-input
              v-model="listQuery.resourceName"
              :placeholder="$t('请输入')"
              clearable
              size="medium"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item :label="$t('视频类型') + '：'">
            <el-checkbox-group v-model="listQuery.videoType">
              <el-checkbox label="0" name="type">{{
                $t("可见光")
              }}</el-checkbox>
              <el-checkbox label="1" name="type">{{ $t("红外") }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item :label="$t('采集来源') + '：'">
            <el-checkbox-group v-model="listQuery.collectSource">
              <el-checkbox label="0" name="type">{{ $t("手动") }}</el-checkbox>
              <el-checkbox label="1" name="type">{{
                $t("巡检任务")
              }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-form>
      </div>
      <div class="search-area-btn btns">
        <div
          @click="serachBtn"
          class="serch-btn cuver-point"
          v-hasPermi="['task:resource:videosearch']"
        >
          {{ $t("搜索") }}
        </div>
        <div
          @click="resetFormBtn('listQuery')"
          class="reset-btn cuver-point"
          v-hasPermi="['data:resouce:videoreset']"
        >
          {{ $t("重置") }}
        </div>
      </div>
    </div>
    <!-- 表格 -->
    <div class="table">
      <div class="self">
        <!-- <div class="search-area-btn btns">
          <div class="serch-btn cuver-point table-top">批量导出</div>
          <div class="serch-btn cuver-point table-top" @click="handleDelete()">
            批量删除
          </div>
          <div @click="clearResourceBtn" class="btn-red cuver-point table-top">
            清空
          </div>
        </div> -->
        <el-table
          ref="tableRef"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%; margin-top: 16px"
          @selection-change="selectionChange"
        >
          <!-- <el-table-column align="center" type="selection"></el-table-column> -->
          <el-table-column
            align="center"
            prop="resourceId"
            :label="$t('视屏ID')"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="createTime"
            :label="$t('录制时间')"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="videoType"
            :label="$t('视频类型')"
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.video_type"
                :value="scope.row.videoType"
              />
            </template>
          </el-table-column>
          <el-table-column
            prop="collectSource"
            :label="$t('采集来源')"
            show-overflow-tooltip
            align="center"
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.collect_source"
                :value="scope.row.collectSource"
              />
            </template>
          </el-table-column>
          <el-table-column
            prop="resourceName"
            :label="$t('文件名')"
            show-overflow-tooltip
            align="center"
            width="500"
          >
          </el-table-column>
          <el-table-column :label="$t('操作')" align="center" width="82">
            <template slot-scope="scope">
              <div class="table-btns">
                <div
                  @click="viewRow(scope.row)"
                  class="serch-btn cuver-point"
                  v-hasPermi="['data:resource:videoview']"
                >
                  {{ $t("查看") }}
                </div>
                <!-- <div
                  @click="educeResource(scope.row)"
                  class="btn-green cuver-point"
                >
                  导出
                </div> -->
                <!-- <div
                  @click="handleDelete(scope.row)"
                  class="btn-red cuver-point"
                >
                  删除
                </div> -->
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagenation">
        <pagination
          :total="total"
          :page.sync="listQuerySubmit.pageNum"
          :limit.sync="listQuerySubmit.pageSize"
          @pagination="getTableList"
        >
        </pagination>
      </div>
    </div>
    <!-- 清空dialog -->
    <el-dialog
      :title="$t('确认删除')"
      :visible.sync="dialogVisible"
      width="560px"
      @close="dialogVisible = false"
    >
      <div class="content">
        <div class="line-one">
          <img src="../../../../assets/images/data/resource/mark.png" alt="" />
          <span class="confirm-font">{{ $t("确认删除") }}：&nbsp;&nbsp; </span>
          <span class="warn-font">{{ $t("图片库视频库音频库") }}</span>
        </div>
        <div class="line-two">
          <span class="warn-font">{{ $t("注删除后将无法恢复") }}</span>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <div @click="confirmClearAll" class="serch-btn">
          {{ $t("确认删除") }}
        </div>
        <div
          class="reset-btn"
          style="margin-left: 15px"
          @click="dialogVisible = false"
        >
          {{ $t("取消") }}
        </div>
      </div>
    </el-dialog>
    <!-- 视频dialog -->
    <el-dialog
      :title="$t('查看')"
      :visible.sync="viewVisible"
      width="560px"
      @close="closeDialog"
    >
      <div class="dialog-lineone">
        <div>{{ $t("拍摄时间") + "：" }}{{ createTime }}</div>
        <div>{{ $t("文件名") + "：" }}{{ resourceName }}</div>
        <div @click="downLoad" class="el-icon-download cursor-pointer"></div>
      </div>
      <div>
        <video controls style="width: 100%" ref="videoRef">
          <source :src="resourceUrl" type="video/mp4" />
        </video>
      </div>
      <div slot="footer" class="dialog-footer">
        <div slot="footer" style="display: flex; justify-content: flex-end">
          <div class="reset-btn" @click="viewVisible = false">
            {{ $t("关闭") }}
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  API_resourceList,
  API_resourceDel,
  API_resourceClearAll,
} from "@/api/data/resource";
export default {
  dicts: ["picture_type", "collect_source", "video_type"],
  data() {
    return {
      pickerOptionsStart: {
        disabledDate: (time) => {
          let endDateVal = this.listQuery.endTime;
          if (endDateVal) {
            return time.getTime() >= new Date(endDateVal).getTime();
          }
        },
      },
      // 结束日期
      pickerOptionsEnd: {
        disabledDate: (time) => {
          let beginDateVal = this.listQuery.startTime;
          if (beginDateVal) {
            return (
              time.getTime() <=
              new Date(beginDateVal).getTime() - 1 * 24 * 60 * 60 * 1000
            );
          }
        },
      },
      dialogVisible: false, //弹框
      viewVisible: false, //资源弹框
      sevePort: window.location.protocol + "//" + window.location.host,
      resourceType: "1",
      listQuery: {
        startTime: null,
        endTime: null,
        resourceName: null,
        videoType: [],
        collectSource: [],
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      listQuerySubmit: {},
      createTime: "", //录制时间
      resourceName: "", //文件名
      resourceUrl: "", //图片资源
      tableData: [], //表格数据
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      downLoadUrl: "",
    };
  },
  watch: {},
  created() {
    this.listQuerySubmit = Object.assign({}, this.listQuery);
    this.getTableList();
  },
  methods: {
    /**采集弹框 close */
    closeDialog() {
      this.viewVisible = false;
      this.$refs["videoRef"].pause();
    },
    /**查看 */
    viewRow(row) {
      this.resourceUrl = ""; //清空之前数据
      this.createTime = row.createTime;
      this.resourceName = row.resourceName;
      this.$nextTick(() => {
        this.$refs.videoRef.src = this.sevePort + row.resourceUrl;
      });
      this.downLoadUrl = row.resourceUrl;
      this.viewVisible = true;
    },
    downLoad() {
      this.$download.resource(this.downLoadUrl);
    },
    /**导出 */
    educeResource(rowInfo) {
      console.warn("rowInfo", rowInfo);
    },
    /** 重置按钮操作 */
    resetFormBtn(formName) {
      this.listQuery = {
        startTime: null,
        endTime: null,
        resourceName: null,
        videoType: [],
        collectSource: [],
        pageNum: 1,
        pageSize: 10,
      };
      this.serachBtn();
    },
    /**搜索 */
    serachBtn() {
      this.listQuery.pageNum = 1;
      this.listQuerySubmit = Object.assign({}, this.listQuery);
      this.getTableList();
    },
    /** table多选 */
    selectionChange(selection) {
      this.ids = selection.map((item) => item.resourceId);
      this.single = selection.length !== 1;
    },

    /**采集资源数据 */
    getTableList() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      // 视频类型
      let videoType = this.listQuerySubmit.videoType;
      if (videoType && videoType.length > 0) {
        if (videoType.indexOf(",") == -1) {
          videoType = String(videoType);
        } else {
          videoType = videoType.join(",");
        }
      }
      // 采集来源
      let collectSource = this.listQuerySubmit.collectSource;
      if (collectSource && collectSource.length > 0) {
        if (collectSource.indexOf(",") == -1) {
          collectSource = String(collectSource);
        } else {
          collectSource = collectSource.join(",");
        }
      }
      API_resourceList({
        resourceType: this.resourceType,
        ...this.listQuerySubmit,
        videoType: videoType,
        collectSource: collectSource,
      })
        .then((res) => {
          if (res.code == 200) {
            if (res.rows.length > 0) {
              this.tableData = res.rows;
            } else {
              this.tableData = [];
            }
            this.total = Number(res.total);
            this.listQuery = Object.assign({}, this.listQuerySubmit);
          }
        })
        .finally(() => {
          loading.close();
        });
    },
    /** 批量删除按钮操作 */
    handleDelete(row) {
      const resourceIds = row.resourceId || this.ids;
      this.$modal
        .confirm(
          this.$t("是否确认删除资源库编号为") +
            resourceIds +
            this.$t("的数据项")
        )
        .then(function () {
          return API_resourceDel(resourceIds);
        })
        .then(() => {
          this.getTableList();
          this.$modal.msgSuccess(this.$t("删除成功"));
        })
        .catch(() => {});
    },
    /**清空 */
    clearResourceBtn() {
      this.dialogVisible = true;
    },
    /**确认清空 */
    confirmClearAll() {
      return API_resourceClearAll().then((res) => {
        if (res.code == 200) {
          this.dialogVisible = false;
          this.$message.success(this.$t("已清空"));
          this.getTableList();
        }
      });
    },

    /** 导出按钮操作 */
    // handleExport() {
    //   this.download(
    //     "data.resource/resource.export",
    //     {
    //       ...this.queryParams,
    //     },
    //     `resource_${new Date().getTime()}.xlsx`
    //   );
    // },
  },
};
</script>
<style lang="scss" scoped>
.table {
  width: 100%;
  height: 738px;
  border-top: 1px dashed rgba(219, 255, 251, 0.2);
  padding: 24px;
  box-sizing: border-box;
  position: relative;
  .btns {
    display: flex;
    width: 100%;
    justify-content: flex-start;
    div:nth-child(2) {
      margin: 0 16px;
    }
  }
  .table-btns {
    display: flex;
    div {
      display: flex;
      width: 46px;
      height: 28px;
      justify-content: center;
      align-items: center;
      font-size: 12px;
    }
    div:nth-child(2) {
      margin: 0 10px;
    }
  }
  .pagenation {
    position: absolute;
    bottom: 30px;
    right: 20px;
  }
}
// 弹框内部样式
.el-dialog {
  position: relative;
  .content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 16px;
  }
  .line-one {
    img {
      width: 24px;
      height: 24px;
      vertical-align: middle;
    }
    .confirm-font {
      display: inline-block;
      margin-left: 16px;
    }
    .warn-font {
      color: #ffad30;
    }
  }
  .line-two {
    margin-top: 22px;
  }
  .dialog-footer {
    display: flex;
    justify-content: flex-end;
  }
}
// 小手样式
.cuver-point {
  cursor: pointer;
}
//采集资源弹框样式
/**弹框样式 */
.dialog-lineone {
  display: flex;
  margin: 0 0 20px 0;
  div:nth-child(1) {
    width: 50%;
  }
  div:nth-child(2) {
    width: 45%;
  }
  div:nth-child(3) {
    width: 5%;
  }
}

::v-deep {
  .el-tabs__item {
    color: rgba(255, 255, 255, 0.5);
  }
  .el-tabs__nav-wrap::after {
    background-color: rgba(241, 243, 249, 0.2) !important;
  }
  .el-tabs__nav-scroll {
    padding: 0 35px;
  }
  .el-tabs__item.is-active {
    color: rgba(0, 209, 255, 1);
  }
  .el-tabs__active-bar {
    width: 50px !important;
    left: -5px;
    background-color: rgba(0, 209, 255, 1);
  }
}
::v-deep {
  .el-dialog:not(.is-fullscreen) {
    margin-top: 30vh !important;
  }
  .self {
    .el-table__body-wrapper {
      width: 100%;
      max-height: 531px;
      overflow: auto;
    }
  }
}
</style>
